<template>
  <view class="container">
    <block v-if="isload">
      <view class="top">
        <view class="f1">需支付金额</view>
        <view class="f2" v-if="payorder.score == 0">
          <block
            v-if="
              typeid == 6 &&
              vip_card_pay == 1 &&
              finalAmount > 0 &&
              payorder.money != finalAmount
            "
          >
            <text class="t1"
              >￥<text
                class="t1"
                style="text-decoration: line-through; color: gray"
                >{{ payorder.money }}</text
              ></text
            ><text class="t2">{{ finalAmount }}</text>
          </block>

          <block v-else>
            <text class="t1">￥</text
            ><text class="t2">{{ payorder.money }}</text>
          </block>
        </view>

        <view class="f2" v-else-if="payorder.money > 0 && payorder.score > 0">
          <block v-if="typeid == 6 && vip_card_pay == 1 && finalAmount > 0">
            <text class="t1"
              >￥<text
                class="t1"
                style="text-decoration: line-through; color: gray"
                >{{ payorder.money }}</text
              ></text
            ><text class="t2">{{ finalAmount }}</text>
          </block>
          <block v-else>
            <text class="t1">￥</text
            ><text class="t2">{{ payorder.money }}</text>
          </block>
          <text style="font-size: 28rpx"
            >+{{ payorder.score }}{{ t("积分") }}</text
          >
        </view>

        <view class="f2" v-else
          ><text class="t3">{{ payorder.score }}{{ t("积分") }}</text></view
        >
        <view
          class="f3"
          @tap="goto"
          :data-url="detailurl"
          v-if="detailurl != ''"
          >订单详情<text class="iconfont iconjiantou"></text
        ></view>
      </view>
      <view class="paytype">
        <view class="f1">选择支付方式：</view>
        <block v-if="payorder.money == 0 && payorder.score > 0">
          <view class="f2">
            <view
              class="item"
              v-if="moneypay == 1 || moneypay == 2"
              @tap.stop="changeradio"
              data-typeid="1"
            >
              <view class="t1 flex">
                <image
                  class="img"
                  :src="static_url + '/static/img/pay-money.png'"
                />
                <view class="flex-col"
                  ><text>{{ t("积分") }}支付</text
                  ><text style="font-size: 22rpx; font-weight: normal"
                    >剩余{{ t("积分")
                    }}<text style="color: #fc5729">{{
                      userinfo.score
                    }}</text></text
                  ></view
                >
              </view>
              <view
                class="radio"
                :style="
                  typeid == '1' ? 'background:' + t('color1') + ';border:0' : ''
                "
              >
                <image class="radio-img" src="/static/img/checkd.png" />
              </view>
            </view>
          </view>
        </block>
        <block v-else>
          <view class="f2">
            <block v-if="moneypay != 2">
              <view
                class="item"
                v-if="
                  wxpay == 1 &&
                  (wxpay_type == 0 ||
                    wxpay_type == 1 ||
                    wxpay_type == 2 ||
                    wxpay_type == 3)
                "
                @tap.stop="changeradio"
                data-typeid="2"
              >
                <view class="t1">
                  <image
                    class="img"
                    src="/static/img/withdraw-weixin.png"
                  />微信支付
                </view>
                <view
                  class="radio"
                  :style="
                    typeid == '2'
                      ? 'background:' + t('color1') + ';border:0'
                      : ''
                  "
                >
                  <image class="radio-img" src="/static/img/checkd.png" />
                </view>
              </view>
              <view
                class="item"
                v-if="wxpay == 1 && wxpay_type == 22"
                @tap.stop="changeradio"
                data-typeid="22"
              >
                <view class="t1">
                  <image
                    class="img"
                    src="/static/img/withdraw-weixin.png"
                  />微信支付
                </view>
                <view
                  class="radio"
                  :style="
                    typeid == '22'
                      ? 'background:' + t('color1') + ';border:0'
                      : ''
                  "
                >
                  <image class="radio-img" src="/static/img/checkd.png" />
                </view>
              </view>

              <view
                class="item"
                v-if="alipay == 2"
                @tap.stop="changeradio"
                data-typeid="23"
              >
                <view class="t1">
                  <image
                    class="img"
                    src="/static/img/withdraw-alipay.png"
                  />支付宝支付
                </view>
                <view
                  class="radio"
                  :style="
                    typeid == '23'
                      ? 'background:' + t('color1') + ';border:0'
                      : ''
                  "
                >
                  <image class="radio-img" src="/static/img/checkd.png" />
                </view>
              </view>

              <!-- <view class="item" v-if="alipay==2" @tap.stop="changeradio" data-typeid="24">
							<view class="t1"><image class="img" :src="static_url + '/static/img/pay-money.png'"/>银联支付</view>
							<view class="radio" :style="typeid=='24' ? 'background:'+t('color1')+';border:0' : ''"><image class="radio-img" src="/static/img/checkd.png"/></view>
						</view> -->

              <view
                class="item"
                v-if="alipay == 1"
                @tap.stop="changeradio"
                data-typeid="3"
              >
                <view class="t1">
                  <image
                    class="img"
                    src="/static/img/withdraw-alipay.png"
                  />支付宝支付
                </view>
                <view
                  class="radio"
                  :style="
                    typeid == '3'
                      ? 'background:' + t('color1') + ';border:0'
                      : ''
                  "
                >
                  <image class="radio-img" src="/static/img/checkd.png" />
                </view>
              </view>

              <block v-if="more_alipay == 1">
                <view
                  class="item"
                  v-for="(item, index) in more_alipay_data"
                  @tap.stop="changeradio"
                  :data-typeid="item.typeid"
                >
                  <view class="t1">
                    <image
                      class="img"
                      src="/static/img/withdraw-alipay.png"
                    />{{ item.name }}
                  </view>
                  <view
                    class="radio"
                    :style="
                      typeid == item.typeid
                        ? 'background:' + t('color1') + ';border:0'
                        : ''
                    "
                  >
                    <image class="radio-img" src="/static/img/checkd.png" />
                  </view>
                </view>
              </block>

              <view
                class="item"
                v-if="paypal == 1"
                @tap.stop="changeradio"
                data-typeid="51"
              >
                <view class="t1">
                  <image class="img" src="/static/img/paypal.png" />PayPal支付
                </view>
                <view
                  class="radio"
                  :style="
                    typeid == '51'
                      ? 'background:' + t('color1') + ';border:0'
                      : ''
                  "
                >
                  <image class="radio-img" src="/static/img/checkd.png" />
                </view>
              </view>

              <view
                class="item"
                v-if="baidupay == 1"
                @tap.stop="changeradio"
                data-typeid="11"
              >
                <view class="t1">
                  <image
                    class="img"
                    :src="static_url + '/static/img/pay-money.png'"
                  />在线支付
                </view>
                <view
                  class="radio"
                  :style="
                    typeid == '11'
                      ? 'background:' + t('color1') + ';border:0'
                      : ''
                  "
                >
                  <image class="radio-img" src="/static/img/checkd.png" />
                </view>
              </view>
              <view
                class="item"
                v-if="toutiaopay == 1"
                @tap.stop="changeradio"
                data-typeid="12"
              >
                <view class="t1">
                  <image
                    class="img"
                    :src="static_url + '/static/img/pay-money.png'"
                  />在线支付
                </view>
                <view
                  class="radio"
                  :style="
                    typeid == '12'
                      ? 'background:' + t('color1') + ';border:0'
                      : ''
                  "
                >
                  <image class="radio-img" src="/static/img/checkd.png" />
                </view>
              </view>
            </block>
            <!-- && payorder.type=='facepay' -->
            <view
              class="item"
              v-if="moneypay == 1 || moneypay == 2"
              @tap.stop="changeradio"
              data-typeid="1"
            >
              <view class="t1 flex">
                <image
                  class="img"
                  :src="static_url + '/static/img/pay-money.png'"
                />
                <view class="flex-col"
                  ><text>{{ t("余额") }}支付</text
                  ><text style="font-size: 22rpx; font-weight: normal"
                    >可用{{ t("余额")
                    }}<text style="color: #fc5729"
                      >￥{{ userinfo.money }}</text
                    ></text
                  ></view
                >
              </view>
              <view
                class="radio"
                :style="
                  typeid == '1' ? 'background:' + t('color1') + ';border:0' : ''
                "
              >
                <image class="radio-img" src="/static/img/checkd.png" />
              </view>
            </view>
            <view
              class="item"
              v-if="(moneypay == 1 || moneypay == 2) && 0"
              @tap.stop="changeradio"
              data-typeid="13"
            >
              <view class="t1 flex">
                <image
                  class="img"
                  :src="static_url + '/static/img/order4.png'"
                />
                <view class="flex-col"
                  ><text>{{ t("分期") }}支付</text>
                </view>
              </view>
              <view
                class="radio"
                :style="
                  typeid == '13'
                    ? 'background:' + t('color1') + ';border:0'
                    : ''
                "
              >
                <image class="radio-img" src="/static/img/checkd.png" />
              </view>
            </view>
            <view
              class="item"
              v-if="vip_card_pay == 1"
              @tap.stop="changeradio"
              data-typeid="6"
            >
              <view class="t1 flex">
                <image class="img" :src="static_url + '/static/img/vip.png'" />
                <view class="flex-col">
                  <text>{{
                    selectedCard ? selectedCard.card_name : "VIP卡支付"
                  }}</text>

                  <text
                    v-if="selectedCard"
                    style="font-size: 22rpx; font-weight: normal"
                    >可用{{ t("余额")
                    }}<text style="color: #fc5729"
                      >￥{{ selectedCard.money }}</text
                    >
                  </text>

                  <text v-else style="font-size: 22rpx; font-weight: normal"
                    >使用VIP卡享折扣
                  </text>
                </view>
              </view>
              <view
                class="radio"
                :style="
                  typeid == '6' ? 'background:' + t('color1') + ';border:0' : ''
                "
              >
                <image class="radio-img" src="/static/img/checkd.png" />
              </view>
            </view>
          </view>
        </block>
      </view>
      <button
        class="btn"
        @tap="topay"
        :style="{ background: t('color1') }"
        v-if="typeid != '0'"
      >
        立即支付
      </button>
      <button
        class="btn"
        @tap="topay2"
        v-if="cancod == 1"
        style="background: rgba(126, 113, 246, 0.5)"
      >
        {{ codtxt
        }}<text style="font-size: 24rpx" v-if="cod_frontmoney > 0"
          >(需付定金￥{{ cod_frontmoney }})</text
        >
      </button>
      <button
        class="btn"
        @tap="topayMonth"
        v-if="pay_month == 1"
        :style="{ background: t('color1') }"
      >
        {{ pay_month_txt }}
      </button>
      <block v-if="daifu">
        <button
          class="btn daifu-btn"
          @tap="todaifu"
          v-if="
            getplatform() == 'h5' ||
            getplatform() == 'mp' ||
            getplatform() == 'app'
          "
        >
          {{ daifu_txt }}
        </button>
        <button class="btn daifu-btn" open-type="share" v-else>
          {{ daifu_txt }}
        </button>
      </block>

      <!-- <button class="btn" @tap="showVipCardList" style="background: #606060;">VIP卡支付</button> -->

      <uni-popup id="dialogInput" ref="dialogInput" type="dialog">
        <uni-popup-dialog
          mode="input"
          title="支付密码"
          value=""
          placeholder="请输入支付密码"
          @confirm="getpwd"
          password="true"
        ></uni-popup-dialog>
      </uni-popup>

      <!-- VIP卡支付弹窗 -->
      <uni-popup ref="vipCardPopup" type="bottom">
        <view class="vip-card-popup">
          <view class="popup-header">
            <text class="title"
              >选择
              <text class="title-vip" :style="{ background: t('color1') }"
                >VIP</text
              >
              卡 ({{ vipCards.filter((c) => c.status != 2).length }})</text
            >
            <text
              class="close"
              @tap="closeVipCardList"
              :style="{ color: t('color1') }"
              >×</text
            >
          </view>
          <view
            v-if="vipCards.length == 0"
            class="card-tip"
            style="text-align: center; margin-top: 150rpx"
          >
            <!-- <view>选择VIP卡支付，可享受折扣优惠</view> -->
            <!-- <view>您当前还没VIP卡，请先到个人中心购买后使用</view> -->
            <view>{{
              card_tip == ""
                ? "您当前还没VIP卡，请先到个人中心购买后使用"
                : card_tip
            }}</view>
          </view>
          <scroll-view scroll-y class="card-list" v-else>
            <view
              class="card-item"
              v-for="(card, index) in vipCards.filter((c) => c.status != 2)"
              :key="index"
              @tap="selectVipCard(card)"
              :class="{ selected: selectedCard && selectedCard.id === card.id }"
              :style="{
                background:
                  selectedCard && selectedCard.id === card.id
                    ? t('color2')
                    : '#ede8e1',
              }"
            >
              <image class="card-bg" :src="card.icon" mode="aspectFill"></image>
              <view class="card-info">
                <!-- <view class="card-name">{{ card.card_name }}</view> -->
                <view class="card-balance">余额: ¥{{ card.money }}</view>
                <view
                  class="card-usetime"
                  v-if="
                    card.use_time_end != '' &&
                    card.use_time_end &&
                    card.bind_mid != 0
                  "
                  >使用时间: {{ card.use_time_start.substring(0, 10) }}至{{
                    card.use_time_end.substring(0, 10)
                  }}
                </view>
                <!-- <view class="card-usetime"
                  >使用时间:{{ "2025-06-14 00:00:00".substring(0, 10) }}至{{
                    "2026-06-14 00:00:00".substring(0, 10)
                  }}
                </view> -->
              </view>
              <!-- removeTrailingZero(card.discount * 100) -->
              <view class="card-discount" v-if="card.discount < 1">
                <view class="discount-text"
                  >{{ (card.discount * 100) / 10
                  }}<view :style="{ fontSize: 27 + 'rpx' }">折</view></view
                >
              </view>
              <!-- v-if="selectedCard && selectedCard.id === card.id" -->
              <view
                class="select-icon"
                :style="{
                  background:
                    selectedCard && selectedCard.id === card.id
                      ? t('color1')
                      : '#C9CACA',
                }"
              >
                <image src="/static/img/checkd.png" mode="aspectFit"></image>
              </view>
            </view>
          </scroll-view>
          <!-- <view class="popup-footer">
						<view class="price-info">
							<text class="label">支付金额</text>
							<text class="original-price">¥{{ payorder.money }}</text>
							<text class="discount-price" v-if="discountAmount > 0">已优惠: ¥{{ discountAmount }}</text>
						</view>
						<button class="pay-btn" :disabled="!selectedCard" @tap="handleVipCardPay"
							:style="{ background: selectedCard ? t('color1') : '#999' }">
							确认支付 ¥{{ finalAmount }}
						</button>
					</view> -->
        </view>
      </uni-popup>

      <block v-if="give_coupon_show">
        <view class="give-coupon flex-x-center flex-y-center">
          <view class="coupon-block">
            <image
              :src="static_url + '/static/img/coupon-top.png'"
              style="width: 630rpx; height: 330rpx"
            >
            </image>
            <view
              @tap="give_coupon_close"
              :data-url="give_coupon_close_url"
              class="coupon-del flex-x-center flex-y-center"
            >
              <image src="/static/img/coupon-del.png"></image>
            </view>
            <view class="flex-x-center">
              <view class="coupon-info">
                <view class="flex-x-center coupon-get"
                  >获得{{ give_coupon_num }}张{{ t("优惠券") }}</view
                >
                <view style="background: #f5f5f5; padding: 10rpx 0">
                  <block
                    v-for="(item, index) in give_coupon_list"
                    :key="item.id"
                  >
                    <block v-if="index < 3">
                      <view class="coupon-coupon">
                        <view
                          :class="item.type == 1 ? 'pt_img1' : 'pt_img2'"
                        ></view>
                        <view
                          class="pt_left"
                          :class="item.type == 1 ? '' : 'bg2'"
                        >
                          <view class="f1" v-if="item.type == 1"
                            ><text class="t0">￥</text
                            ><text class="t1">{{ item.money }}</text>
                          </view>
                          <view class="f1" v-if="item.type == 2">礼品券</view>
                          <view class="f1" v-if="item.type == 3"
                            ><text class="t1">{{ item.limit_count }}</text
                            ><text class="t2">次</text></view
                          >
                          <view class="f1" v-if="item.type == 4">抵运费</view>
                          <view
                            class="f2"
                            v-if="item.type == 1 || item.type == 4"
                          >
                            <text v-if="item.minprice > 0"
                              >满{{ item.minprice }}元可用</text
                            >
                            <text v-else>无门槛</text>
                          </view>
                        </view>
                        <view class="pt_right">
                          <view class="f1">
                            <view class="t1">{{ item.name }}</view>
                            <view class="t2" v-if="item.type == 1">代金券</view>
                            <view class="t2" v-if="item.type == 2">礼品券</view>
                            <view class="t2" v-if="item.type == 3">计次券</view>
                            <view class="t2" v-if="item.type == 4"
                              >运费抵扣券</view
                            >
                            <!-- <view class="t4" v-if="item.bid>0">适用商家：{{item.bname}}</view> -->
                            <!-- <view class="t3">有效期至 {{item.yxqdate}}</view> -->
                          </view>
                        </view>
                        <view class="coupon_num" v-if="item.givenum > 1"
                          >×{{ item.givenum }}
                        </view>
                      </view>
                    </block>
                  </block>
                </view>
                <view
                  @tap="goto"
                  data-url="/pages/coupon/mycoupon"
                  class="flex-x-center coupon-btn"
                >
                  前往查看</view
                >
              </view>
            </view>
          </view>
        </view>
      </block>
      <uni-popup
        id="dialogOpenWeapp"
        ref="dialogOpenWeapp"
        type="dialog"
        :maskClick="false"
      >
        <view
          style="
            background: #fff;
            padding: 50rpx;
            position: relative;
            border-radius: 20rpx;
          "
        >
          <view
            style="
              height: 80px;
              line-height: 80px;
              width: 200px;
              margin: 0 auto;
              font-size: 18px;
              text-align: center;
              font-weight: bold;
              text-align: center;
              color: #333;
            "
          >
            恭喜您支付成功</view
          >
          <!-- #ifdef H5 -->
          <wx-open-launch-weapp
            :username="payorder.payafter_username"
            :path="payorder.payafter_path"
          >
            <script type="text/wxtag-template">
              <div style="background:#FD4A46;height:50px;line-height: 50px;width:200px;margin:0 auto;border-radius:5px;margin-top:15px;color: #fff;font-size: 15px;font-weight:bold;text-align:center">{{payorder.payafterbtntext}}</div>
            </script>
          </wx-open-launch-weapp>
          <!-- #endif -->
          <view
            style="
              height: 50px;
              line-height: 50px;
              width: 200px;
              margin: 0 auto;
              border-radius: 5px;
              color: #66f;
              font-size: 14px;
              text-align: center;
            "
            @tap="goto"
            :data-url="detailurl"
            >查看订单详情</view
          >
        </view>
      </uni-popup>

      <uni-popup
        id="dialogPayconfirm"
        ref="dialogPayconfirm"
        type="dialog"
        :maskClick="false"
      >
        <uni-popup-dialog
          type="info"
          title="支付确认"
          content="是否已完成支付"
          @confirm="PayconfirmFun"
        ></uni-popup-dialog>
      </uni-popup>

      <!-- 元宝s -->
      <view
        v-if="yuanbaopay == 1 && open_pay"
        style="
          width: 100%;
          height: 100%;
          position: fixed;
          z-index: 10;
          background-color: #000;
          opacity: 0.45;
          top: 0;
        "
      >
      </view>
      <view
        v-if="yuanbaopay == 1 && open_pay"
        style="
          width: 90%;
          position: fixed;
          z-index: 11;
          left: 5%;
          top: 25%;
          background-color: #fff;
        "
      >
        <view class="paytype">
          <view class="f2">
            <view
              class="item"
              v-if="
                wxpay == 1 &&
                (wxpay_type == 0 ||
                  wxpay_type == 1 ||
                  wxpay_type == 2 ||
                  wxpay_type == 3)
              "
              @tap.stop="changeradio"
              data-typeid="2"
            >
              <view class="t1">
                <image
                  class="img"
                  src="/static/img/withdraw-weixin.png"
                />微信支付
              </view>
              <view
                class="radio"
                :style="
                  typeid == '2' ? 'background:' + t('color1') + ';border:0' : ''
                "
              >
                <image class="radio-img" src="/static/img/checkd.png" />
              </view>
            </view>
            <view
              class="item"
              v-if="wxpay == 1 && wxpay_type == 22"
              @tap.stop="changeradio"
              data-typeid="22"
            >
              <view class="t1">
                <image
                  class="img"
                  src="/static/img/withdraw-weixin.png"
                />微信支付
              </view>
              <view
                class="radio"
                :style="
                  typeid == '22'
                    ? 'background:' + t('color1') + ';border:0'
                    : ''
                "
              >
                <image class="radio-img" src="/static/img/checkd.png" />
              </view>
            </view>

            <view
              class="item"
              v-if="alipay == 2"
              @tap.stop="changeradio"
              data-typeid="23"
            >
              <view class="t1">
                <image
                  class="img"
                  src="/static/img/withdraw-alipay.png"
                />支付宝支付
              </view>
              <view
                class="radio"
                :style="
                  typeid == '23'
                    ? 'background:' + t('color1') + ';border:0'
                    : ''
                "
              >
                <image class="radio-img" src="/static/img/checkd.png" />
              </view>
            </view>
            <view
              class="item"
              v-if="alipay == 1"
              @tap.stop="changeradio"
              data-typeid="3"
            >
              <view class="t1">
                <image
                  class="img"
                  src="/static/img/withdraw-alipay.png"
                />支付宝支付
              </view>
              <view
                class="radio"
                :style="
                  typeid == '3' ? 'background:' + t('color1') + ';border:0' : ''
                "
              >
                <image class="radio-img" src="/static/img/checkd.png" />
              </view>
            </view>

            <block v-if="more_alipay == 1">
              <view
                class="item"
                v-for="(item, index) in more_alipay_data"
                @tap.stop="changeradio"
                :data-typeid="item.typeid"
              >
                <view class="t1">
                  <image class="img" src="/static/img/withdraw-alipay.png" />{{
                    item.name
                  }}
                </view>
                <view
                  class="radio"
                  :style="
                    typeid == item.typeid
                      ? 'background:' + t('color1') + ';border:0'
                      : ''
                  "
                >
                  <image class="radio-img" src="/static/img/checkd.png" />
                </view>
              </view>
            </block>

            <view
              class="item"
              v-if="baidupay == 1"
              @tap.stop="changeradio"
              data-typeid="11"
            >
              <view class="t1">
                <image
                  class="img"
                  :src="static_url + '/static/img/pay-money.png'"
                />在线支付
              </view>
              <view
                class="radio"
                :style="
                  typeid == '11'
                    ? 'background:' + t('color1') + ';border:0'
                    : ''
                "
              >
                <image class="radio-img" src="/static/img/checkd.png" />
              </view>
            </view>
            <view
              class="item"
              v-if="toutiaopay == 1"
              @tap.stop="changeradio"
              data-typeid="12"
            >
              <view class="t1">
                <image
                  class="img"
                  :src="static_url + '/static/img/pay-money.png'"
                />在线支付
              </view>
              <view
                class="radio"
                :style="
                  typeid == '12'
                    ? 'background:' + t('color1') + ';border:0'
                    : ''
                "
              >
                <image class="radio-img" src="/static/img/checkd.png" />
              </view>
            </view>
            <view
              class="item"
              v-if="moneypay == 1"
              @tap.stop="changeradio"
              data-typeid="1"
            >
              <view class="t1 flex">
                <image
                  class="img"
                  :src="static_url + '/static/img/pay-money.png'"
                />
                <view class="flex-col"
                  ><text>{{ t("余额") }}支付</text
                  ><text style="font-size: 22rpx; font-weight: normal"
                    >可用余额<text style="color: #fc5729"
                      >￥{{ userinfo.money }}</text
                    ></text
                  ></view
                >
              </view>
              <view
                class="radio"
                :style="
                  typeid == '1' ? 'background:' + t('color1') + ';border:0' : ''
                "
              >
                <image class="radio-img" src="/static/img/checkd.png" />
              </view>
            </view>
            <view
              class="item"
              v-if="(moneypay == 1 || moneypay == 2) && 0"
              @tap.stop="changeradio"
              data-typeid="13"
            >
              <view class="t1 flex">
                <image
                  class="img"
                  :src="static_url + '/static/img/order4.png'"
                />
                <view class="flex-col"
                  ><text>{{ t("分期") }}支付</text>
                </view>
              </view>
              <view
                class="radio"
                :style="
                  typeid == '13'
                    ? 'background:' + t('color1') + ';border:0'
                    : ''
                "
              >
                <image class="radio-img" src="/static/img/checkd.png" />
              </view>
            </view>
          </view>
        </view>
        <view style="overflow: hidden; width: 100%">
          <view style="width: 300rpx; float: left">
            <view>
              <button
                class="btn"
                @tap="close_pay"
                style="margin-bottom: 20rpx; background-color: #999"
              >
                取消
              </button>
            </view>
          </view>
          <view style="width: 300rpx; float: right">
            <view>
              <button
                class="btn"
                @tap="topay"
                :style="{ background: t('color1') }"
                v-if="typeid != '0'"
                style="margin-bottom: 20rpx"
              >
                确定
              </button>
            </view>
          </view>
        </view>
      </view>
      <!-- 元宝e -->
    </block>
    <view
      @tap="closeInvite"
      v-if="invite_status && invite_free"
      style="
        width: 100%;
        height: 100%;
        background-color: #000;
        position: fixed;
        opacity: 0.5;
        z-index: 99;
        top: 0;
      "
    >
    </view>
    <view
      v-if="invite_status && invite_free"
      style="
        width: 700rpx;
        margin: 0 auto;
        position: fixed;
        top: 10%;
        left: 25rpx;
        z-index: 100;
      "
    >
      <view
        @tap="gotoInvite"
        style="
          background-color: #fff;
          border-radius: 20rpx;
          overflow: hidden;
          width: 100%;
          min-height: 700rpx;
        "
      >
        <image
          :src="invite_free.pic"
          mode="widthFix"
          style="width: 100%; height: auto"
        ></image>
      </view>
      <view
        @tap="closeInvite"
        v-if="invite_status && invite_free"
        style="
          width: 80rpx;
          height: 80rpx;
          line-height: 80rpx;
          text-align: center;
          font-size: 30rpx;
          background-color: #fff;
          margin: 0 auto;
          border-radius: 50%;
          margin-top: 20rpx;
        "
      >
        X
      </view>
    </view>

    <loading v-if="loading"></loading>
    <dp-tabbar :opt="opt"></dp-tabbar>
    <popmsg ref="popmsg"></popmsg>
  </view>
</template>

<script>
var app = getApp();

export default {
  data() {
    return {
      opt: {},
      loading: false,
      isload: false,
      menuindex: -1,
      pre_url: app.globalData.pre_url,
      static_url: app.globalData.static_url,

      detailurl: "",
      tourl: "",
      pay_success_url: "",
      typeid: "0",
      wxpay: 0,
      wxpay_type: 0,
      alipay: 0,
      baidupay: 0,
      toutiaopay: 0,
      moneypay: 0,
      cancod: 0,
      cod_frontmoney: 0,
      cod_payorderid: 0,
      daifu: 0,
      daifu_txt: "好友代付",
      pay_month: 0,
      pay_transfer: 0,
      codtxt: "",
      pay_month_txt: "",
      give_coupon_list: [],
      give_coupon_num: 0,
      userinfo: [],
      paypwd: "",
      hiddenmodalput: true,
      payorder: {},
      tmplids: [],
      give_coupon_show: false,
      give_coupon_close_url: "",
      more_alipay: 0,
      more_alipay_data: [],
      paypal: 0,

      //元宝支付
      yuanbao_money: 0, //现金
      total_yuanbao: 0, //总元宝
      yuanbao_msg: "", //元宝文字描述
      yuanbaopay: 0, //是否开启元宝支付
      open_pay: false, //打开支付选项
      pay_type: "", //支付类型（新增）

      invite_free: "",
      invite_status: false,
      free_tmplids: "",
      sharepic: app.globalData.initdata.logo,
      vip_card_pay: 0,
      vipCards: [
        // {
        // 	id: 1,
        // 	name: '超级会员卡',
        // 	balance: 2000,
        // 	discount: 8.8,
        // 	bgImg: 'https://heda123.oss-cn-guangzhou.aliyuncs.com/upload/3/20250121/e41d7fe8ead48f06290c699d6d6d36e9.jpg'
        // }
      ],
      selectedCard: null,
      discountAmount: 0,
      finalAmount: 0,
      card_tip: "",
    };
  },
  onShareAppMessage: function () {
    var that = this;
    var title = "您有一份好友代付待查收，请尽快处理！";
    var sharepic = that.sharepic;
    var sharelink =
      app.globalData.pre_url +
      "/h5/" +
      app.globalData.aid +
      ".html#/pages/pay/daifu?scene=id_" +
      that.payorder.id;
    var sharedata = this._sharewx({
      title: title,
      tolink: sharelink,
      pic: sharepic,
    });
    console.log("pay share data");
    console.log(sharedata);
    return sharedata;
  },
  onShareTimeline: function () {
    var that = this;
    var title = "您有一份好友代付待查收，请尽快处理1！";
    var sharepic = that.sharepic;
    var sharelink =
      app.globalData.pre_url +
      "/h5/" +
      app.globalData.aid +
      ".html#/pages/pay/daifu?scene=id_" +
      that.payorder.id;
    var sharewxdata = this._sharewx({
      title: title,
      tolink: sharelink,
      pic: sharepic,
    });
    var query = sharewxdata.path.split("?")[1] + "&seetype=circle";
    var link =
      app.globalData.pre_url +
      "/h5/" +
      app.globalData.aid +
      ".html#" +
      sharewxdata.path.split("?")[0] +
      "&seetype=circle";
    return {
      title: sharewxdata.title,
      imageUrl: sharewxdata.imageUrl,
      query: query,
      link: link,
    };
  },

  onLoad: function (opt) {
    this.opt = app.getopts(opt);
    console.log(this.opt);
    if (this.opt.tourl) this.tourl = decodeURIComponent(this.opt.tourl);
  },
  onShow() {
    if (this.typeid == "1") {
      var typeid = this.typeid;
      this.getdata(typeid);
      //这里重新设置vip密码后避免重置页面数据
    } else if (this.typeid == "6") {
      this.getVipCardList(this.selectedCard.id);
    } else {
      this.getdata();
    }
  },
  onPullDownRefresh: function () {
    this.getdata();
  },
  methods: {
    getdata: function (type = null) {
      var that = this;
      that.loading = true;
      var thisurl = "";
      if (app.globalData.platform == "mp" || app.globalData.platform == "h5") {
        thisurl = location.href;
      }
      app.post(
        "Pay/pay",
        {
          orderid: Number(that.opt.id),
          thisurl: thisurl,
          tourl: that.tourl,
          scene: app.globalData.scene,
        },
        function (res) {
          that.loading = false;
          if (res.status == 0) {
            app.error(res.msg);
            return;
          }

          that.wxpay = res.wxpay;
          that.wxpay_type = res.wxpay_type;
          that.alipay = res.alipay;
          that.baidupay = res.baidupay;
          that.toutiaopay = res.toutiaopay;
          that.cancod = res.cancod;
          that.codtxt = res.codtxt;
          that.cod_frontmoney = res.cod_frontmoney || 0;
          that.cod_payorderid = res.cod_payorderid || 0;
          that.daifu = res.daifu;
          that.daifu_txt = res.daifu_txt;
          that.pay_money = res.pay_money;
          that.pay_money_txt = res.pay_money_txt;
          that.moneypay = res.moneypay;
          that.pay_transfer = res.pay_transfer;
          that.pay_transfer_info = res.pay_transfer_info;
          that.pay_month = res.pay_month;
          that.pay_month_txt = res.pay_month_txt;
          that.payorder = res.payorder;
          that.userinfo = res.userinfo;
          that.tmplids = res.tmplids;
          that.give_coupon_list = res.give_coupon_list;
          that.vip_card_pay = res.vip_card_pay;
          if (that.give_coupon_list) {
            for (var i in that.give_coupon_list) {
              that.give_coupon_num += that.give_coupon_list[i]["givenum"];
            }
          }
          that.detailurl = res.detailurl;
          that.tourl = res.tourl;
          that.pay_success_url = res.pay_success_url;
          that.paypal = res.paypal || 0;

          that.more_alipay = res.more_alipay;
          that.more_alipay_data = res.more_alipay_data || [];
          that.yuanbao_money = res.yuanbao_money;
          that.total_yuanbao = res.total_yuanbao;
          that.yuanbao_msg = res.yuanbao_msg;
          that.yuanbaopay = res.yuanbaopay;
          if (that.wxpay) {
            if (that.wxpay_type == 22) {
              that.typeid = 22;
            } else {
              that.typeid = 2;
            }
          } else if (that.moneypay) {
            that.typeid = 1;
          } else if (that.alipay) {
            that.typeid = 3;
            if (that.alipay == 2) {
              that.typeid = 23;
            }
          } else if (that.more_alipay) {
            that.typeid = that.more_alipay_data[0].typeid;
          } else if (that.baidupay) {
            that.typeid = 11;
          } else if (that.toutiaopay) {
            that.typeid = 12;
          }
          if (that.payorder.money == 0 && that.payorder.score > 0) {
            that.typeid = 1;
          }
          if (res.invite_free) {
            that.invite_free = res.invite_free;
          }
          if (res.free_tmplids) {
            that.free_tmplids = res.free_tmplids;
          }
          that.loaded();

          //追加指定支付类型，设置余额支付密码后可以回归到指定支付类型
          if (type) {
            that.typeid = type;
          }
          if (that.opt && that.opt.paypal == "success") {
            that.typeid = 51;
            app.showLoading("支付中");
            app.post(
              "Pay/paypalRedirect",
              {
                orderid: that.opt.id,
                paymentId: that.opt.paymentId,
                PayerID: that.opt.PayerID,
              },
              function (res) {
                app.showLoading(false);
                if (res.status == 1) {
                  app.success(res.msg);
                  that.subscribeMessage(function () {
                    if (that.invite_free) {
                      that.invite_status = true;
                    } else {
                      setTimeout(function () {
                        if (
                          that.give_coupon_list &&
                          that.give_coupon_list.length > 0
                        ) {
                          that.give_coupon_show = true;
                          that.give_coupon_close_url = that.tourl;
                        } else {
                          //uni.navigateBack();
                          that.afterPayToUrl();
                        }
                      }, 1000);
                    }
                  });
                } else if (res.status == 0) {
                  app.error(res.msg);
                }
              }
            );
          }
        }
      );
    },
    getpwd: function (done, val) {
      var flag = 1;
      if (this.typeid == 6) {
        flag = 6;
      }
      this.paypwd = val;
      this.topay({
        currentTarget: {
          dataset: {
            typeid: flag,
          },
        },
      });
    },
    changeradio: function (e) {
      var that = this;
      var typeid = e.currentTarget.dataset.typeid;
      that.typeid = typeid;
      console.log(typeid);
      if (typeid == 6) {
        that.showVipCardList();
      }
    },
    topay: function (e) {
      var that = this;
      var typeid = that.typeid;
      var orderid = this.payorder.id;
      if (e.currentTarget.dataset.isfrontpay == 1) {
        var orderid = this.cod_payorderid;
      }
      if (typeid == 1) {
        //余额支付
        //用户若没设置支付密码去设置
        //console.log(that.userinfo,that.userinfo.haspwd);return;
        if (!that.userinfo.haspwd) {
          uni.navigateTo({
            url: "/pagesExt/my/paypwd",
          });
          return;
        }
        if (that.userinfo.haspwd && that.paypwd == "") {
          that.$refs.dialogInput.open();
          return;
        }
        // '确定用' + that.t('余额') + '支付吗?'
        app.confirm("是否确认支付吗？", function () {
          app.showLoading("提交中");
          app.post(
            "Pay/pay",
            {
              op: "submit",
              orderid: orderid,
              typeid: typeid,
              paypwd: that.paypwd,
              pay_type: that.pay_type,
            },
            function (res) {
              app.showLoading(false);
              if (res.status == 0) {
                app.error(res.msg);
                return;
              }
              if (res.status == 2) {
                app.success(res.msg);
                that.subscribeMessage(function () {
                  if (that.invite_free) {
                    that.invite_status = true;
                  } else {
                    setTimeout(function () {
                      if (
                        that.give_coupon_list &&
                        that.give_coupon_list.length > 0
                      ) {
                        that.give_coupon_show = true;
                        that.give_coupon_close_url = that.tourl;
                      } else {
                        that.afterPayToUrl();
                      }
                    }, 1000);
                  }
                });
                return;
              }
            }
          );
        });
      } else if (typeid == 2) {
        //微信支付
        console.log(app);
        app.showLoading("提交中");
        app.post(
          "Pay/pay",
          {
            op: "submit",
            orderid: orderid,
            typeid: typeid,
          },
          function (res) {
            app.showLoading(false);
            if (res.status == 0) {
              app.error(res.msg);
              return;
            }
            if (res.status == 2) {
              //无需付款
              app.success(res.msg);
              that.subscribeMessage(function () {
                if (that.invite_free) {
                  that.invite_status = true;
                } else {
                  setTimeout(function () {
                    if (
                      that.give_coupon_list &&
                      that.give_coupon_list.length > 0
                    ) {
                      that.give_coupon_show = true;
                      that.give_coupon_close_url = that.tourl;
                    } else {
                      that.afterPayToUrl();
                    }
                  }, 1000);
                }
              });
              return;
            }
            var opt = res.data;
            if (app.globalData.platform == "wx") {
              if (that.payorder.type == "shop" || that.wxpay_type == 2) {
                if (opt.orderInfo) {
                  console.log("requestOrderPayment1");
                  wx.requestOrderPayment({
                    timeStamp: opt.timeStamp,
                    nonceStr: opt.nonceStr,
                    package: opt.package,
                    signType: opt.signType ? opt.signType : "MD5",
                    paySign: opt.paySign,
                    orderInfo: opt.orderInfo,
                    success: function (res2) {
                      app.success("付款完成");
                      that.subscribeMessage(function () {
                        if (that.invite_free) {
                          that.invite_status = true;
                        } else {
                          setTimeout(function () {
                            if (
                              that.give_coupon_list &&
                              that.give_coupon_list.length > 0
                            ) {
                              that.give_coupon_show = true;
                              that.give_coupon_close_url = that.tourl;
                            } else {
                              that.gotourl(that.tourl, "reLaunch");
                            }
                          }, 1000);
                        }
                      });
                    },
                    fail: function (res2) {
                      //app.alert(JSON.stringify(res2))
                    },
                  });
                } else {
                  console.log("requestOrderPayment2");
                  wx.requestOrderPayment({
                    timeStamp: opt.timeStamp,
                    nonceStr: opt.nonceStr,
                    package: opt.package,
                    signType: opt.signType ? opt.signType : "MD5",
                    paySign: opt.paySign,
                    success: function (res2) {
                      app.success("付款完成");
                      that.subscribeMessage(function () {
                        if (that.invite_free) {
                          that.invite_status = true;
                        } else {
                          setTimeout(function () {
                            if (
                              that.give_coupon_list &&
                              that.give_coupon_list.length > 0
                            ) {
                              that.give_coupon_show = true;
                              that.give_coupon_close_url = that.tourl;
                            } else {
                              that.gotourl(that.tourl, "reLaunch");
                            }
                          }, 1000);
                        }
                      });
                    },
                    fail: function (res2) {
                      //app.alert(JSON.stringify(res2))
                    },
                  });
                }
              } else {
                uni.requestPayment({
                  provider: "wxpay",
                  timeStamp: opt.timeStamp,
                  nonceStr: opt.nonceStr,
                  package: opt.package,
                  signType: opt.signType ? opt.signType : "MD5",
                  paySign: opt.paySign,
                  success: function (res2) {
                    app.success("付款完成");
                    that.subscribeMessage(function () {
                      if (that.invite_free) {
                        that.invite_status = true;
                      } else {
                        setTimeout(function () {
                          if (
                            that.give_coupon_list &&
                            that.give_coupon_list.length > 0
                          ) {
                            that.give_coupon_show = true;
                            that.give_coupon_close_url = that.tourl;
                          } else {
                            that.gotourl(that.tourl, "reLaunch");
                          }
                        }, 1000);
                      }
                    });
                  },
                  fail: function (res2) {
                    //app.alert(JSON.stringify(res2))
                  },
                });
              }
            } else if (app.globalData.platform == "mp") {
              // #ifdef H5
              function jsApiCall() {
                WeixinJSBridge.invoke(
                  "getBrandWCPayRequest",
                  opt,
                  function (res) {
                    if (res.err_msg == "get_brand_wcpay_request:ok") {
                      app.success("付款完成");
                      that.subscribeMessage(function () {
                        if (that.invite_free) {
                          that.invite_status = true;
                        } else {
                          setTimeout(function () {
                            if (
                              that.give_coupon_list &&
                              that.give_coupon_list.length > 0
                            ) {
                              that.give_coupon_show = true;
                              that.give_coupon_close_url = that.tourl;
                            } else {
                              that.gotourl(that.tourl, "reLaunch");
                            }
                          }, 1000);
                        }
                      });
                    } else {
                    }
                  }
                );
              }
              if (typeof WeixinJSBridge == "undefined") {
                if (document.addEventListener) {
                  document.addEventListener(
                    "WeixinJSBridgeReady",
                    jsApiCall,
                    false
                  );
                } else if (document.attachEvent) {
                  document.attachEvent("WeixinJSBridgeReady", jsApiCall);
                  document.attachEvent("onWeixinJSBridgeReady", jsApiCall);
                }
              } else {
                jsApiCall();
              }
              // #endif
              /*
						var jweixin = require('jweixin-module');
						jweixin.chooseWXPay({
							timestamp: opt.timeStamp, // 支付签名时间戳，注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
							nonceStr: opt.nonceStr, // 支付签名随机串，不长于 32 位
							package: opt.package, // 统一支付接口返回的prepay_id参数值，提交格式如：prepay_id=\*\*\*）
							signType: opt.signType, // 签名方式，默认为'SHA1'，使用新版支付需传入'MD5'
							paySign: opt.paySign, // 支付签名
							success: function (res2) {
								// 支付成功后的回调函数
								app.success('付款完成');
								that.subscribeMessage(function () {
									setTimeout(function () {
										if (that.give_coupon_list && that.give_coupon_list.length > 0) {
											that.give_coupon_show = true;
											that.give_coupon_close_url = that.tourl;
										} else {
											that.gotourl(that.tourl,'reLaunch');
										}
									}, 1000);
								});
							}
						});
						*/
            } else if (app.globalData.platform == "h5") {
              location.href =
                opt.wx_url +
                "&redirect_url=" +
                encodeURIComponent(
                  location.href.split("#")[0] + "#" + that.tourl
                );
            } else if (app.globalData.platform == "app") {
              console.log(opt);
              uni.requestPayment({
                provider: "wxpay",
                orderInfo: opt,
                success: function (res2) {
                  app.success("付款完成");
                  that.subscribeMessage(function () {
                    if (that.invite_free) {
                      that.invite_status = true;
                    } else {
                      setTimeout(function () {
                        if (
                          that.give_coupon_list &&
                          that.give_coupon_list.length > 0
                        ) {
                          that.give_coupon_show = true;
                          that.give_coupon_close_url = that.tourl;
                        } else {
                          that.gotourl(that.tourl, "reLaunch");
                        }
                      }, 1000);
                    }
                  });
                },
                fail: function (res2) {
                  console.log(res2);
                  //app.alert(JSON.stringify(res2))
                },
              });
            } else if (app.globalData.platform == "qq") {
              qq.requestWxPayment({
                url: opt.wx_url,
                referer: opt.referer,
                success(res) {
                  that.subscribeMessage(function () {
                    if (that.invite_free) {
                      that.invite_status = true;
                    } else {
                      setTimeout(function () {
                        if (
                          that.give_coupon_list &&
                          that.give_coupon_list.length > 0
                        ) {
                          that.give_coupon_show = true;
                          that.give_coupon_close_url = that.tourl;
                        } else {
                          that.gotourl(that.tourl, "reLaunch");
                        }
                      }, 1000);
                    }
                  });
                },
                fail(res) {},
              });
            }
          }
        );
      } else if (typeid == 3 || (typeid >= 302 && typeid <= 330)) {
        //支付宝支付
        if (app.globalData.platform == "mp") {
          app.goto(
            "/pages/index/webView2?orderid=" +
              orderid +
              "&typeid=" +
              typeid +
              "&aid=" +
              app.globalData.aid +
              "&platform=" +
              app.globalData.platform +
              "&session_id=" +
              app.globalData.session_id
          );
          return;
        }
        app.showLoading("提交中");
        app.post(
          "Pay/pay",
          {
            op: "submit",
            orderid: orderid,
            typeid: typeid,
          },
          function (res) {
            console.log(res);
            app.showLoading(false);
            if (res.status == 0) {
              app.error(res.msg);
              return;
            }
            if (res.status == 2) {
              //无需付款
              app.success(res.msg);
              that.subscribeMessage(function () {
                if (that.invite_free) {
                  that.invite_status = true;
                } else {
                  setTimeout(function () {
                    if (
                      that.give_coupon_list &&
                      that.give_coupon_list.length > 0
                    ) {
                      that.give_coupon_show = true;
                      that.give_coupon_close_url = that.tourl;
                    } else {
                      that.afterPayToUrl();
                    }
                  }, 1000);
                }
              });
              return;
            }
            var opt = res.data;
            if (app.globalData.platform == "alipay") {
              uni.requestPayment({
                provider: "alipay",
                orderInfo: opt.trade_no,
                success: function (res2) {
                  console.log(res2);
                  if (res2.resultCode == "6001") {
                    return;
                  }
                  app.success("付款完成");
                  that.subscribeMessage(function () {
                    if (that.invite_free) {
                      that.invite_status = true;
                    } else {
                      setTimeout(function () {
                        if (
                          that.give_coupon_list &&
                          that.give_coupon_list.length > 0
                        ) {
                          that.give_coupon_show = true;
                          that.give_coupon_close_url = that.tourl;
                        } else {
                          that.gotourl(that.tourl, "reLaunch");
                        }
                      }, 1000);
                    }
                  });
                },
                fail: function (res2) {
                  //app.alert(JSON.stringify(res2))
                },
              });
            } else if (
              app.globalData.platform == "mp" ||
              app.globalData.platform == "h5"
            ) {
              document.body.innerHTML = res.data;
              document.forms["alipaysubmit"].submit();
            } else if (app.globalData.platform == "app") {
              console.log("------------alipay----------");
              console.log(opt);
              console.log("------------alipay end----------");
              uni.requestPayment({
                provider: "alipay",
                orderInfo: opt,
                success: function (res2) {
                  console.log("------------success----------");
                  console.log(res2);
                  app.success("付款完成");
                  that.subscribeMessage(function () {
                    if (that.invite_free) {
                      that.invite_status = true;
                    } else {
                      setTimeout(function () {
                        if (
                          that.give_coupon_list &&
                          that.give_coupon_list.length > 0
                        ) {
                          that.give_coupon_show = true;
                          that.give_coupon_close_url = that.tourl;
                        } else {
                          that.gotourl(that.tourl, "reLaunch");
                        }
                      }, 1000);
                    }
                  });
                },
                fail: function (res2) {
                  console.log(res2);
                  //app.alert(JSON.stringify(res2))
                },
              });
            }
          }
        );
      } else if (typeid == "11") {
        app.showLoading("提交中");
        app.post(
          "Pay/pay",
          {
            op: "submit",
            orderid: orderid,
            typeid: typeid,
          },
          function (res) {
            app.showLoading(false);
            swan.requestPolymerPayment({
              orderInfo: res.orderInfo,
              success: function (res2) {
                app.success("付款完成");
                that.subscribeMessage(function () {
                  if (that.invite_free) {
                    that.invite_status = true;
                  } else {
                    setTimeout(function () {
                      if (
                        that.give_coupon_list &&
                        that.give_coupon_list.length > 0
                      ) {
                        that.give_coupon_show = true;
                        that.give_coupon_close_url = that.tourl;
                      } else {
                        that.gotourl(that.tourl, "reLaunch");
                      }
                    }, 1000);
                  }
                });
              },
              fail: function (res2) {
                if (res2.errCode != 2) {
                  app.alert(JSON.stringify(res2));
                }
              },
            });
          }
        );
      } else if (typeid == "12") {
        app.showLoading("提交中");
        app.post(
          "Pay/pay",
          {
            op: "submit",
            orderid: orderid,
            typeid: typeid,
          },
          function (res) {
            app.showLoading(false);
            console.log(res.orderInfo);
            tt.pay({
              service: 5,
              orderInfo: res.orderInfo,
              success: function (res2) {
                if (res2.code === 0) {
                  app.success("付款完成");
                  that.subscribeMessage(function () {
                    if (that.invite_free) {
                      that.invite_status = true;
                    } else {
                      setTimeout(function () {
                        if (
                          that.give_coupon_list &&
                          that.give_coupon_list.length > 0
                        ) {
                          that.give_coupon_show = true;
                          that.give_coupon_close_url = that.tourl;
                        } else {
                          that.gotourl(that.tourl, "reLaunch");
                        }
                      }, 1000);
                    }
                  });
                }
              },
              fail: function (res2) {
                app.alert(JSON.stringify(res2));
              },
            });
          }
        );
      } else if (typeid == "22") {
        if (app.globalData.platform == "wx") {
          wx.login({
            success: function (res) {
              if (res.code) {
                app.showLoading("提交中");
                app.post(
                  "Pay/getYunMpauthParams",
                  {
                    jscode: res.code,
                  },
                  function (res) {
                    app.showLoading(false);
                    app.post(
                      "https://showmoney.cn/scanpay/fixed/mpauth",
                      res.params,
                      function (res2) {
                        console.log(res2.sessionKey);
                        app.post(
                          "Pay/getYunUnifiedParams",
                          {
                            orderid: orderid,
                            sessionKey: res2.sessionKey,
                          },
                          function (res3) {
                            app.post(
                              "https://showmoney.cn/scanpay/unified",
                              res3.params,
                              function (res4) {
                                if (res4.respcd == "09") {
                                  wx.requestPayment({
                                    timeStamp: res4.timeStamp,
                                    nonceStr: res4.nonceStr,
                                    package: res4.package,
                                    signType: res4.mpSignType,
                                    paySign: res4.mpSign,
                                    success: function success(result) {
                                      app.success("付款完成");
                                      that.subscribeMessage(function () {
                                        if (that.invite_free) {
                                          that.invite_status = true;
                                        } else {
                                          setTimeout(function () {
                                            if (
                                              that.give_coupon_list &&
                                              that.give_coupon_list.length > 0
                                            ) {
                                              that.give_coupon_show = true;
                                              that.give_coupon_close_url =
                                                that.tourl;
                                            } else {
                                              that.gotourl(
                                                that.tourl,
                                                "reLaunch"
                                              );
                                            }
                                          }, 1000);
                                        }
                                      });
                                    },
                                    fail: function (res5) {
                                      //app.alert(JSON.stringify(res5))
                                    },
                                  });
                                } else {
                                  app.alert(res4.errorDetail);
                                }
                              }
                            );
                          }
                        );
                      }
                    );
                  }
                );
              } else {
                console.log("登录失败！" + res.errMsg);
              }
            },
          });
        } else {
          var url =
            app.globalData.baseurl +
            "Pay/pay" +
            "&aid=" +
            app.globalData.aid +
            "&platform=" +
            app.globalData.platform +
            "&session_id=" +
            app.globalData.session_id;
          url += "&op=submit&orderid=" + orderid + "&typeid=22";
          location.href = url;
        }
      } else if (typeid == "23") {
        //var url = app.globalData.baseurl + 'Pay/pay'+'&aid=' + app.globalData.aid + '&platform=' + app.globalData.platform + '&session_id=' + app.globalData.session_id;
        //url += '&op=submit&orderid='+orderid+'&typeid=23';
        //location.href = url;

        app.goto(
          "/pages/index/webView2?orderid=" +
            orderid +
            "&typeid=23" +
            "&aid=" +
            app.globalData.aid +
            "&platform=" +
            app.globalData.platform +
            "&session_id=" +
            app.globalData.session_id
        );
        return;
        app.showLoading("提交中");
        app.post(
          "Pay/pay",
          {
            op: "submit",
            orderid: orderid,
            typeid: 23,
          },
          function (res) {
            app.showLoading(false);
            console.log(res);
            app.goto("url::" + res.url);
          }
        );
      } else if (typeid == "24") {
        //var url = app.globalData.baseurl + 'Pay/pay'+'&aid=' + app.globalData.aid + '&platform=' + app.globalData.platform + '&session_id=' + app.globalData.session_id;
        //url += '&op=submit&orderid='+orderid+'&typeid=23';
        //location.href = url;

        app.goto("/pages/index/webView2?orderid=" + orderid + "&typeid=24");
        return;
        app.showLoading("提交中");
        app.post(
          "Pay/pay",
          {
            op: "submit",
            orderid: orderid,
            typeid: 24,
          },
          function (res) {
            app.showLoading(false);
            console.log(res);
            app.goto("url::" + res.url);
          }
        );
      } else if (typeid == "yuanbao") {
        //元宝支付
        console.log(app);
        var total_yuanbao = that.total_yuanbao - 0;
        var u_yuanbao = that.userinfo.yuanbao - 0;
        if (total_yuanbao > u_yuanbao) {
          app.alert(that.t("元宝") + "不足");
          return;
        }
        that.open_pay = true;
        that.pay_type = "yuanbao";
      } else if (typeid == "51") {
        app.showLoading("提交中");
        app.post(
          "Pay/pay",
          {
            op: "submit",
            orderid: orderid,
            typeid: typeid,
          },
          function (res) {
            app.showLoading(false);
            console.log(res);
            if (res.status == 1) {
              if (app.globalData.platform == "app") {
                const wv = plus.webview.create("", "custom-webview", {
                  top: uni.getSystemInfoSync().statusBarHeight + 44,
                });
                wv.loadURL(res.data);
                var currentWebview = that.$scope.$getAppWebview();
                currentWebview.append(wv);
              } else {
                app.goto("url::" + res.data);
              }
            } else {
              app.alert(res.msg);
            }
          }
        );
      } else if (typeid == "13") {
        //分期支付
        app.goto(decodeURIComponent(""), "redirect");
      } else if (typeid == "6") {
        //VIP卡支付
        //用户若没设置支付密码去设置
        //console.log(that.userinfo,that.userinfo.haspwd);return;
        if (that.selectedCard == null) {
          app.error("请先选择VIP卡");
          return;
        }

        if (that.selectedCard.password == "") {
          uni.navigateTo({
            url: "/pagesExt/vip/vippwd?id=" + that.selectedCard.id,
          });
          return;
        }
        if (that.paypwd == "") {
          that.$refs.dialogInput.open();
          return;
        }
        app.confirm(
          "确定用" + that.selectedCard.card_name + "支付吗?",
          function () {
            app.showLoading("提交中");
            app.post(
              "Pay/pay",
              {
                op: "submit",
                orderid: orderid,
                typeid: typeid,
                paypwd: that.paypwd,
                pay_type: that.pay_type,
                member_vip_card_id: that.selectedCard.id,
              },
              function (res) {
                app.showLoading(false);
                if (res.status == 0) {
                  app.error(res.msg);
                  return;
                }
                if (res.status == 2) {
                  app.success(res.msg);
                  that.subscribeMessage(function () {
                    if (that.invite_free) {
                      that.invite_status = true;
                    } else {
                      setTimeout(function () {
                        if (
                          that.give_coupon_list &&
                          that.give_coupon_list.length > 0
                        ) {
                          that.give_coupon_show = true;
                          that.give_coupon_close_url = that.tourl;
                        } else {
                          that.afterPayToUrl();
                        }
                      }, 1000);
                    }
                  });
                  return;
                }
              }
            );
          }
        );
      }
    },
    topay2: function () {
      var that = this;
      var orderid = this.payorder.id;
      if (this.cod_frontmoney > 0) {
        this.topay({
          currentTarget: {
            dataset: {
              isfrontpay: 1,
            },
          },
        });
        return;
      }
      app.confirm("确定要" + that.codtxt + "吗?", function () {
        app.showLoading("提交中");
        app.post(
          "Pay/pay",
          {
            op: "submit",
            orderid: orderid,
            typeid: 4,
          },
          function (res) {
            app.showLoading(false);
            if (res.status == 0) {
              app.error(res.msg);
              return;
            }
            if (res.status == 2) {
              //无需付款
              app.success(res.msg);
              that.subscribeMessage(function () {
                setTimeout(function () {
                  that.afterPayToUrl();
                }, 1000);
              });
              return;
            }
          }
        );
      });
    },
    topayMonth: function () {
      var that = this;
      var orderid = this.payorder.id;
      app.confirm("确定要" + that.pay_month_txt + "支付吗?", function () {
        app.showLoading("提交中");
        app.post(
          "Pay/pay",
          {
            op: "submit",
            orderid: orderid,
            typeid: 41,
          },
          function (res) {
            app.showLoading(false);
            if (res.status == 0) {
              app.error(res.msg);
              return;
            }
            if (res.status == 2) {
              //无需付款
              app.success(res.msg);
              that.subscribeMessage(function () {
                setTimeout(function () {
                  that.afterPayToUrl();
                }, 1000);
              });
              return;
            }
          }
        );
      });
    },
    topayTransfer: function (e) {
      var that = this;
      var orderid = this.payorder.id;
      app.confirm("确定要" + e.currentTarget.dataset.text + "吗?", function () {
        app.showLoading("提交中");
        app.post(
          "Pay/pay",
          {
            op: "submit",
            orderid: orderid,
            typeid: 5,
          },
          function (res) {
            app.showLoading(false);

            if (res.status == 1) {
              //需审核付款
              app.success(res.msg);
              setTimeout(function () {
                that.gotourl("/pagesExt/order/orderlist", "reLaunch");
              }, 1000);
              return;
            } else if (res.status == 2) {
              //无需付款
              app.success(res.msg);
              that.subscribeMessage(function () {});
              setTimeout(function () {
                that.gotourl("transfer?id=" + orderid, "reLaunch");
              }, 1000);
              return;
            } else {
              app.error(res.msg);
              return;
            }
          }
        );
      });
    },
    give_coupon_close: function (e) {
      var that = this;
      var tourl = e.currentTarget.dataset.url;
      this.give_coupon_show = false;
      that.gotourl(tourl, "reLaunch");
    },
    gotourl: function (tourl, opentype) {
      var that = this;
      if (app.globalData.platform == "mp" || app.globalData.platform == "h5") {
        if (tourl.indexOf("miniProgram::") === 0) {
          //其他小程序
          tourl = tourl.slice(13);
          var tourlArr = tourl.split("|");
          console.log(tourlArr);
          that.showOpenWeapp();
          return;
        }
      }
      app.goto(tourl, opentype);
    },
    showOpenWeapp: function () {
      this.$refs.dialogOpenWeapp.open();
    },
    closeOpenWeapp: function () {
      this.$refs.dialogOpenWeapp.close();
    },
    PayconfirmFun: function () {
      this.gotourl(this.tourl, "reLaunch");
    },
    close_pay: function () {
      var that = this;
      that.open_pay = false;
    },
    closeInvite: function () {
      var that = this;
      that.invite_status = false;
      setTimeout(function () {
        if (that.give_coupon_list && that.give_coupon_list.length > 0) {
          that.give_coupon_show = true;
          that.give_coupon_close_url = that.tourl;
        } else {
          that.afterPayToUrl();
        }
      }, 1000);
    },
    gotoInvite: function () {
      var that = this;
      var free_tmplids = that.free_tmplids;
      if (free_tmplids && free_tmplids.length > 0) {
        uni.requestSubscribeMessage({
          tmplIds: free_tmplids,
          success: function (res) {
            console.log(res);
          },
          fail: function (res) {
            console.log(res);
          },
        });
      }
      app.goto("/pagesExt/invite_free/index", "reLaunch");
    },
    todaifu: function (e) {
      var that = this;
      var platform = app.getplatform();
      var id = that.payorder.id;
      if (platform == "mp" || platform == "h5") {
        var sharelink =
          app.globalData.pre_url +
          "/h5/" +
          app.globalData.aid +
          ".html#/pages/pay/daifu?scene=id_" +
          that.payorder.id;
        this._sharemp({
          title: "您有一份好友代付待查收，请尽快处理~",
          link: sharelink,
          pic: that.sharepic,
        });
        app.error("点击右上角发送给好友或分享到朋友圈");
      } else if (platform == "app") {
        uni.showActionSheet({
          itemList: ["发送给微信好友", "分享到微信朋友圈"],
          success: function (res) {
            if (res.tapIndex >= 0) {
              var scene = "WXSceneSession";
              if (res.tapIndex == 1) {
                scene = "WXSenceTimeline";
              }
              var sharedata = {};
              sharedata.provider = "weixin";
              sharedata.type = 0;
              sharedata.scene = scene;
              sharedata.title = "您的好友向您发出了代付请求";
              sharedata.summary = "您有一份好友代付待查收，请尽快处理~";
              sharedata.href =
                app.globalData.pre_url +
                "/h5/" +
                app.globalData.aid +
                ".html#/pages/pay/daifu?scene=id_" +
                that.payorder.id;
              sharedata.imageUrl = "";
              uni.share(sharedata);
            }
          },
        });
      } else {
        app.error("该终端不支持此操作");
      }
    },

    getVipCardList(id = null) {
      let that = this;
      that.card_tip = "数据加载中";
      app.get(
        "MemberVipCard/myCard",
        {
          type: 1,
        },
        function (res) {
          if (res && res.status == 200) {
            if (id) {
              let index = res.data.findIndex((item) => item.id == id);
              if (index == -1) {
                that.selectedCard = null;
              } else {
                that.selectedCard = res.data[index];
              }
            }

            that.vipCards = res.data;
            that.card_tip = "";

            //app.showLoading(false);
          } else {
            //app.showLoading(false);
            app.error(res.msg);
            that.card_tip = "";
          }
        }
      );
    },

    showVipCardList() {
      this.getVipCardList();
      this.$refs.vipCardPopup.open();
    },
    closeVipCardList() {
      this.$refs.vipCardPopup.close();
    },
    // 选择VIP卡
    selectVipCard(card) {
      //console.log(card, this.payorder.money)
      if (Number(card.money) < Number(this.payorder.money)) {
        uni.showToast({
          title: "卡内余额不足",
          icon: "none",
        });
        return;
      }

      // 计算折扣金额
      const originalAmount = parseFloat(this.payorder.money); // 原始金额
      //const discount = parseFloat(card.discount) / 100; // 将百分比转换为小数
      const discount = card.discount; // 将百分比转换为小数

      // 检查 discount 是否合法
      if (isNaN(discount) || discount < 0 || discount > 1) {
        app.error("折扣值不合法，应为 0 到 100 之间的值");
        return;
      }

      this.selectedCard = card;
      this.$refs.vipCardPopup.close();

      // 计算折扣后的金额
      const discountedAmount = originalAmount * discount; // 直接乘以折扣值
      this.discountAmount = (originalAmount - discountedAmount).toFixed(2); // 折扣金额
      this.finalAmount = discountedAmount.toFixed(2); // 最终金额
      this.paypwd = "";
      // console.log('原始金额:', originalAmount);
      // console.log('折扣值:', discount);
      // console.log('折扣金额:', this.discountAmount);
      // console.log('最终金额:', this.finalAmount);
    },
    // VIP卡支付
    handleVipCardPay() {
      if (!this.selectedCard) return;

      const that = this;
      uni.showModal({
        title: "确认支付",
        content: `是否使用${this.selectedCard.name}支付${this.finalAmount}元？`,
        success: (res) => {
          if (res.confirm) {
            // 这里添加实际的VIP卡支付逻辑
            uni.showLoading({
              title: "支付中...",
            });

            // 模拟支付过程
            setTimeout(() => {
              uni.hideLoading();
              uni.showToast({
                title: "支付成功",
                icon: "success",
              });
              that.$refs.vipCardPopup.close();

              // 支付成功后的跳转逻辑
              setTimeout(() => {
                if (that.give_coupon_list && that.give_coupon_list.length > 0) {
                  that.give_coupon_show = true;
                  that.give_coupon_close_url = that.tourl;
                } else {
                  that.gotourl(that.pay_success_url, "reLaunch");
                }
              }, 1500);
            }, 1000);
          }
        },
      });
    },
    removeTrailingZero(num) {
      try {
        // 将数字转换为字符串以便检查最后一位
        const numStr = num.toString();

        // 检查最后一位是否是 '0'
        if (numStr.endsWith("0")) {
          // 去掉最后一位 '0'，并转换回数字
          // 注意：这里使用 Math.floor 来确保结果是一个整数
          // 如果 num 是浮点数且我们希望保留小数部分（如果有的话），
          // 则需要更复杂的逻辑来处理这种情况
          return Math.floor(num / 10);
        } else {
          // 如果最后一位不是 '0'，则直接返回原数字
          return num;
        }
      } catch (error) {
        return num;
      }
    },
    afterPayToUrl() {
      if (this.pay_success_url) {
        this.gotourl(this.pay_success_url, "reLaunch");
      } else {
        this.gotourl(this.tourl, "reLaunch");
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.top {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 60rpx;
}

.top .f1 {
  height: 60rpx;
  line-height: 60rpx;
  color: #939393;
  font-size: 24rpx;
}

.top .f2 {
  color: #101010;
  font-weight: bold;
  font-size: 72rpx;
  height: 120rpx;
  line-height: 120rpx;
}

.top .f2 .t1 {
  font-size: 44rpx;
}

.top .f2 .t3 {
  font-size: 50rpx;
}

.top .f3 {
  color: #fc5729;
  font-size: 26rpx;
  height: 70rpx;
  line-height: 70rpx;
}

.paytype {
  width: 94%;
  margin: 20rpx 3% 80rpx 3%;
  border-radius: 10rpx;
  display: flex;
  flex-direction: column;
  margin-top: 20rpx;
  background: #fff;
}

.paytype .f1 {
  height: 100rpx;
  line-height: 100rpx;
  padding: 0 30rpx;
  color: #333333;
  font-weight: bold;
}

.paytype .f2 {
  padding: 0 30rpx;
}

.paytype .f2 .item {
  border-bottom: 1px solid #f5f5f5;
  height: 100rpx;
  display: flex;
  align-items: center;
}

.paytype .f2 .item:last-child {
  border-bottom: 0;
}

.paytype .f2 .item .t1 {
  flex: 1;
  display: flex;
  align-items: center;
  color: #222222;
  font-size: 30rpx;
  font-weight: bold;
}

.paytype .f2 .item .t1 .img {
  width: 44rpx;
  height: 44rpx;
  margin-right: 40rpx;
}

.paytype .f2 .item .radio {
  flex-shrink: 0;
  width: 36rpx;
  height: 36rpx;
  background: #ffffff;
  border: 3rpx solid #bfbfbf;
  border-radius: 50%;
  margin-right: 10rpx;
}

.paytype .f2 .item .radio .radio-img {
  width: 100%;
  height: 100%;
}

.btn {
  height: 100rpx;
  line-height: 100rpx;
  width: 90%;
  margin: 0 auto;
  border-radius: 10rpx;
  margin-top: 30rpx;
  color: #fff;
  font-size: 30rpx;
  font-weight: bold;
}

.daifu-btn {
  background: #fc5729;
}

.op {
  width: 94%;
  margin: 20rpx 3%;
  display: flex;
  align-items: center;
  margin-top: 40rpx;
}

.op .btn {
  flex: 1;
  height: 100rpx;
  line-height: 100rpx;
  background: #07c160;
  width: 90%;
  margin: 0 10rpx;
  border-radius: 10rpx;
  color: #fff;
  font-size: 28rpx;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
}

.op .btn .img {
  width: 48rpx;
  height: 48rpx;
  margin-right: 20rpx;
}

.vip-card-popup {
  background-color: #fff;
  border-radius: 24rpx 24rpx 0 0;
  min-height: 60vh;
  max-height: 90vh;
  display: flex;
  flex-direction: column;

  .popup-header {
    padding: 8rpx 30rpx;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1rpx solid #f5f5f5;

    .title {
      font-size: 32rpx;
      // font-weight: bold;
      color: #333;

      .title-vip {
        font-size: 33rpx;
        color: #fff;
        margin: 0 10rpx;
        padding: 0rpx 26rpx;
        border-radius: 10rpx;
        position: relative;

        &:before {
          position: absolute;
          top: -4rpx;
          left: 40rpx;
          width: 10rpx;
          height: 10rpx;
          background-color: #fff;
          border-radius: 50%;
          content: "";
          z-index: 9;
          clip-path: inset(40% 0 0 0);
        }

        &:after {
          position: absolute;
          bottom: -4rpx;
          left: 40rpx;
          width: 10rpx;
          height: 10rpx;
          background-color: #f7f8f9;
          border-radius: 50%;
          content: "";
          z-index: 9;
          clip-path: inset(0 0 40% 0);
        }
      }
    }

    .close {
      font-size: 60rpx;
      font-weight: 100;
      color: #999;
      padding: 0 20rpx;
    }
  }

  .card-list {
    flex: 1;
    padding: 20rpx;
    max-height: 60vh;
    padding-top: 0rpx;

    .card-item {
      position: relative;
      height: 250rpx;
      margin-bottom: 20rpx;
      border-radius: 16rpx;
      overflow: hidden;
      box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
      padding: 20rpx 80rpx 20rpx 20rpx;
      background-color: #ede8e1;

      &.selected {
        //border: 3rpx solid #ba1f25;
      }

      .card-bg {
        // position: absolute;
        width: 100%;
        height: 100%;
        z-index: 1;
        border-radius: 16rpx;
      }

      .card-info {
        position: absolute;
        top: 0rpx;
        z-index: 2;
        padding: 30rpx;
        color: #fff;
        height: 100%;
        // text-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.2);

        .card-name {
          font-size: 32rpx;
          font-weight: bold;
          margin-bottom: 10rpx;
        }

        .card-balance {
          color: #ba7934;
          font-size: 26rpx;
          // opacity: 0.9;
          position: absolute;
          top: 90rpx;
          width: 60vw;
        }

        .card-usetime {
          color: #997d60;
          font-size: 26rpx;
          // opacity: 0.9;
          position: absolute;
          bottom: 70rpx;
          width: 80vw;
        }
      }

      .card-discount {
        position: absolute;
        right: 110rpx;
        bottom: 50rpx;
        z-index: 2;
        background: linear-gradient(to right, #f7dfc4, #f7dfc4);
        padding: 0rpx 14rpx;
        border-radius: 8rpx;

        .discount-text {
          /* 关键代码 */
          background: linear-gradient(to right, #ce9655, #e9bc82);
          -webkit-background-clip: text;
          background-clip: text;
          color: transparent;
          font-size: 38rpx;
          display: flex;
          justify-content: center;
          align-items: center;
        }
      }

      .select-icon {
        position: absolute;
        right: 20rpx;
        bottom: 110rpx;
        z-index: 2;
        width: 40rpx;
        height: 40rpx;
        background-color: #ba1f25;
        border-radius: 20rpx;

        image {
          width: 100%;
          height: 100%;
        }
      }
    }
  }

  .popup-footer {
    padding: 30rpx;
    border-top: 1rpx solid #f5f5f5;

    .price-info {
      display: flex;
      align-items: center;
      margin-bottom: 20rpx;

      .label {
        font-size: 28rpx;
        color: #666;
        margin-right: 20rpx;
      }

      .original-price {
        font-size: 36rpx;
        font-weight: bold;
        color: #333;
      }

      .discount-price {
        margin-left: 20rpx;
        font-size: 26rpx;
        color: #ba1f25;
      }
    }

    .pay-btn {
      width: 100%;
      height: 88rpx;
      line-height: 88rpx;
      text-align: center;
      color: #fff;
      font-size: 32rpx;
      font-weight: bold;
      border-radius: 44rpx;
      margin: 0;

      &::after {
        border: none;
      }

      &[disabled] {
        background: #999 !important;
        color: #fff !important;
      }
    }
  }
}
</style>
